package com.linwen.excise.leetcode;

/**
 * @ClassName _1491去掉最低工资和最高工资后的工资平均值
 * @Description TODO
 * @Author zero
 * @DATE 2024/10/7 2:35 PM
 * @Version 1.0
 */
public class _1491去掉最低工资和最高工资后的工资平均值 {
    public static void main(String[] args) {
        _1491去掉最低工资和最高工资后的工资平均值 inst = new _1491去掉最低工资和最高工资后的工资平均值();
        int[] salary = {4000,3000,1000,2000};
        System.out.println(inst.average(salary));

    }

    public double average(int[] salary) {
        int min = salary[0];
        int max = salary[0];
        int sum = 0;
        for (int i : salary) {
            if (min > i) {
                min = i;
            }
            if (max < i) {
                max = i;
            }
            sum += i;
        }
        return (double) (sum - min - max) / (salary.length - 2);
    }
}
